<template>
  <div class="app-container">
    <div class="filter-container"></div>
    <div><el-button type="primary" plain size="mini" @click="toadd">添加管理员</el-button></div>
    <!-- 管理员列表 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="loginName" label="用户名"></el-table-column>
      <el-table-column prop="lastName" label="真实姓名"></el-table-column>
      <el-table-column prop="mobile" label="电话"></el-table-column>
      <el-table-column label="创建时间" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="lastLogTime" label="最后登录时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="" label="操作">
        <template slot-scope="scope">
          <el-button @click="handleClickEdit(scope.row)" type="text" size="small">编辑</el-button>
          <el-button @click="handleClickDelete(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { list, del } from '@/api/sys/admin';

export default {
  data() {
    return {
      tableData: [],
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      list(this.queryParams).then(res => {
        this.tableData = res.result.list;
        this.total = res.result.total;
        this.loading = false;
      });
    },
    toadd() {
      this.$router.push({ path: '/sys/newadmin' });
    },
    handleClickEdit(row) {
      console.info(row);
      this.$router.push({ path: '/sys/newadmin', meta: { title: 'hahah' }, query: { id: row.id } });
    },
    handleClickDelete(row) {
      this.$confirm('是否删除管理员?', '提示', {
        type: 'warning'
      }).then(() => {
        // this.$message('删除');
        this.$confirm('确认删除', '提示', { type: 'warning' }).then(() => {
          del({ adminId: row.id }).then(res => {
            this.$message({
              message: res.message,
              type: 'success'
            });
            this.getList();
          });
        });
      });
    }
  }
};
</script>

<style></style>
